# # -*- coding=utf-8
# from qcloud_cos import CosConfig
# from qcloud_cos import CosS3Client
# from qcloud_cos import CosServiceError
# from qcloud_cos import CosClientError
#
# import sys
# import logging
#
# # 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x
#
# # pip安装指南:pip install -U cos-python-sdk-v5
#
# # cos最新可用地域,参照https://www.qcloud.com/document/product/436/6224
#
# logging.basicConfig(level=logging.INFO, stream=sys.stdout)
#
# # 设置用户属性, 包括secret_id, secret_key, region
# # appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
# secret_id = 'AKIDIuTQBosmT38A0yxKpIf3b1NcgZIjDE4m'     # 替换为用户的secret_id
# secret_key = '7GdM0eNNh9hH6zzKdFxhTPOpqw5GThxF'     # 替换为用户的secret_key
# region = 'ap-beijing-1'    # 替换为用户的region
# token = None               # 使用临时密钥需要传入Token，默认为空,可不填
# config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)  # 获取配置对象
# client = CosS3Client(config)

from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import logging

logging.basicConfig(level=logging.INFO, stream=sys.stdout)

secret_id = 'AKIDIuTQBosmT38A0yxKpIf3b1NcgZIjDE4m'      # 替换为用户的 secretId
secret_key = '7GdM0eNNh9hH6zzKdFxhTPOpqw5GThxF'      # 替换为用户的 secretKey
region = 'ap-beijing'     # 替换为用户的 Region
token = None                # 使用临时密钥需要传入 Token，默认为空，可不填
scheme = 'https'            # 指定使用 http/https 协议来访问 COS，默认为 https，可不填
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
# 2. 获取客户端对象
client = CosS3Client(config)
# 文件流 简单上传
text1 = 'test.txt'
with open('test.txt', 'rb') as fp:
    # 本地路径 简单上传
    response = client.put_object_from_local_file(
        Bucket='test1-1301495777',
        LocalFilePath=r'F:\untitled\project\tracer\app01\test.txt',
        Key=text1,
    )
    print(response['ETag'])




